// 模拟 lodash 中的 flowRight
const _ = require('lodash')
const reverse = arr => arr.reverse()


const first = arr => arr[0]
const toUpper = s => s.toUpperCase()

const fn = _.flowRight(toUpper, first, reverse)

const arr = ['one', 'two', 'three']

// console.log(fn(arr));

// function compose(...args) {
//   return function (value) {
//     return args.reverse().reduce((acc, fn) => fn(acc), value)
//   }
// }
const compose = (...args) => value => args.reverse().reduce((acc, fn) => fn(acc), value)
const f = compose(toUpper, first, reverse)
console.log(f(arr));

// 23 函数的组合要满足结合律